<?php


abstract class BaseFunrProfesional extends BaseObject  implements Persistent {


	
	protected static $peer;


	
	protected $funr_profesional_id;


	
	protected $funpro_nombre;


	
	protected $funpro_apellido;


	
	protected $funpro_sexo;


	
	protected $funpro_edad;


	
	protected $funpro_telefono;


	
	protected $funpro_estado;


	
	protected $funr_tipoprofesional_id;

	
	protected $aFunrTipoprofesional;

	
	protected $collFuntFichapsicos;

	
	protected $lastFuntFichapsicoCriteria = null;

	
	protected $collFuntFichasocials;

	
	protected $lastFuntFichasocialCriteria = null;

	
	protected $alreadyInSave = false;

	
	protected $alreadyInValidation = false;

	
	public function getFunrProfesionalId()
	{

		return $this->funr_profesional_id;
	}

	
	public function getFunproNombre()
	{

		return $this->funpro_nombre;
	}

	
	public function getFunproApellido()
	{

		return $this->funpro_apellido;
	}

	
	public function getFunproSexo()
	{

		return $this->funpro_sexo;
	}

	
	public function getFunproEdad()
	{

		return $this->funpro_edad;
	}

	
	public function getFunproTelefono()
	{

		return $this->funpro_telefono;
	}

	
	public function getFunproEstado()
	{

		return $this->funpro_estado;
	}

	
	public function getFunrTipoprofesionalId()
	{

		return $this->funr_tipoprofesional_id;
	}

	
	public function setFunrProfesionalId($v)
	{

		
		
		if ($v !== null && !is_int($v) && is_numeric($v)) {
			$v = (int) $v;
		}

		if ($this->funr_profesional_id !== $v) {
			$this->funr_profesional_id = $v;
			$this->modifiedColumns[] = FunrProfesionalPeer::FUNR_PROFESIONAL_ID;
		}

	} 
	
	public function setFunproNombre($v)
	{

		
		
		if ($v !== null && !is_string($v)) {
			$v = (string) $v; 
		}

		if ($this->funpro_nombre !== $v) {
			$this->funpro_nombre = $v;
			$this->modifiedColumns[] = FunrProfesionalPeer::FUNPRO_NOMBRE;
		}

	} 
	
	public function setFunproApellido($v)
	{

		
		
		if ($v !== null && !is_string($v)) {
			$v = (string) $v; 
		}

		if ($this->funpro_apellido !== $v) {
			$this->funpro_apellido = $v;
			$this->modifiedColumns[] = FunrProfesionalPeer::FUNPRO_APELLIDO;
		}

	} 
	
	public function setFunproSexo($v)
	{

		
		
		if ($v !== null && !is_string($v)) {
			$v = (string) $v; 
		}

		if ($this->funpro_sexo !== $v) {
			$this->funpro_sexo = $v;
			$this->modifiedColumns[] = FunrProfesionalPeer::FUNPRO_SEXO;
		}

	} 
	
	public function setFunproEdad($v)
	{

		
		
		if ($v !== null && !is_int($v) && is_numeric($v)) {
			$v = (int) $v;
		}

		if ($this->funpro_edad !== $v) {
			$this->funpro_edad = $v;
			$this->modifiedColumns[] = FunrProfesionalPeer::FUNPRO_EDAD;
		}

	} 
	
	public function setFunproTelefono($v)
	{

		
		
		if ($v !== null && !is_string($v)) {
			$v = (string) $v; 
		}

		if ($this->funpro_telefono !== $v) {
			$this->funpro_telefono = $v;
			$this->modifiedColumns[] = FunrProfesionalPeer::FUNPRO_TELEFONO;
		}

	} 
	
	public function setFunproEstado($v)
	{

		
		
		if ($v !== null && !is_string($v)) {
			$v = (string) $v; 
		}

		if ($this->funpro_estado !== $v) {
			$this->funpro_estado = $v;
			$this->modifiedColumns[] = FunrProfesionalPeer::FUNPRO_ESTADO;
		}

	} 
	
	public function setFunrTipoprofesionalId($v)
	{

		
		
		if ($v !== null && !is_int($v) && is_numeric($v)) {
			$v = (int) $v;
		}

		if ($this->funr_tipoprofesional_id !== $v) {
			$this->funr_tipoprofesional_id = $v;
			$this->modifiedColumns[] = FunrProfesionalPeer::FUNR_TIPOPROFESIONAL_ID;
		}

		if ($this->aFunrTipoprofesional !== null && $this->aFunrTipoprofesional->getFunrTipoprofesionalId() !== $v) {
			$this->aFunrTipoprofesional = null;
		}

	} 
	
	public function hydrate(ResultSet $rs, $startcol = 1)
	{
		try {

			$this->funr_profesional_id = $rs->getInt($startcol + 0);

			$this->funpro_nombre = $rs->getString($startcol + 1);

			$this->funpro_apellido = $rs->getString($startcol + 2);

			$this->funpro_sexo = $rs->getString($startcol + 3);

			$this->funpro_edad = $rs->getInt($startcol + 4);

			$this->funpro_telefono = $rs->getString($startcol + 5);

			$this->funpro_estado = $rs->getString($startcol + 6);

			$this->funr_tipoprofesional_id = $rs->getInt($startcol + 7);

			$this->resetModified();

			$this->setNew(false);

						return $startcol + 8; 
		} catch (Exception $e) {
			throw new PropelException("Error populating FunrProfesional object", $e);
		}
	}

	
	public function delete($con = null)
	{
		if ($this->isDeleted()) {
			throw new PropelException("This object has already been deleted.");
		}

		if ($con === null) {
			$con = Propel::getConnection(FunrProfesionalPeer::DATABASE_NAME);
		}

		try {
			$con->begin();
			FunrProfesionalPeer::doDelete($this, $con);
			$this->setDeleted(true);
			$con->commit();
		} catch (PropelException $e) {
			$con->rollback();
			throw $e;
		}
	}

	
	public function save($con = null)
	{
		if ($this->isDeleted()) {
			throw new PropelException("You cannot save an object that has been deleted.");
		}

		if ($con === null) {
			$con = Propel::getConnection(FunrProfesionalPeer::DATABASE_NAME);
		}

		try {
			$con->begin();
			$affectedRows = $this->doSave($con);
			$con->commit();
			return $affectedRows;
		} catch (PropelException $e) {
			$con->rollback();
			throw $e;
		}
	}

	
	protected function doSave($con)
	{
		$affectedRows = 0; 		if (!$this->alreadyInSave) {
			$this->alreadyInSave = true;


												
			if ($this->aFunrTipoprofesional !== null) {
				if ($this->aFunrTipoprofesional->isModified()) {
					$affectedRows += $this->aFunrTipoprofesional->save($con);
				}
				$this->setFunrTipoprofesional($this->aFunrTipoprofesional);
			}


						if ($this->isModified()) {
				if ($this->isNew()) {
					$pk = FunrProfesionalPeer::doInsert($this, $con);
					$affectedRows += 1; 										 										 
					$this->setFunrProfesionalId($pk);  
					$this->setNew(false);
				} else {
					$affectedRows += FunrProfesionalPeer::doUpdate($this, $con);
				}
				$this->resetModified(); 			}

			if ($this->collFuntFichapsicos !== null) {
				foreach($this->collFuntFichapsicos as $referrerFK) {
					if (!$referrerFK->isDeleted()) {
						$affectedRows += $referrerFK->save($con);
					}
				}
			}

			if ($this->collFuntFichasocials !== null) {
				foreach($this->collFuntFichasocials as $referrerFK) {
					if (!$referrerFK->isDeleted()) {
						$affectedRows += $referrerFK->save($con);
					}
				}
			}

			$this->alreadyInSave = false;
		}
		return $affectedRows;
	} 
	
	protected $validationFailures = array();

	
	public function getValidationFailures()
	{
		return $this->validationFailures;
	}

	
	public function validate($columns = null)
	{
		$res = $this->doValidate($columns);
		if ($res === true) {
			$this->validationFailures = array();
			return true;
		} else {
			$this->validationFailures = $res;
			return false;
		}
	}

	
	protected function doValidate($columns = null)
	{
		if (!$this->alreadyInValidation) {
			$this->alreadyInValidation = true;
			$retval = null;

			$failureMap = array();


												
			if ($this->aFunrTipoprofesional !== null) {
				if (!$this->aFunrTipoprofesional->validate($columns)) {
					$failureMap = array_merge($failureMap, $this->aFunrTipoprofesional->getValidationFailures());
				}
			}


			if (($retval = FunrProfesionalPeer::doValidate($this, $columns)) !== true) {
				$failureMap = array_merge($failureMap, $retval);
			}


				if ($this->collFuntFichapsicos !== null) {
					foreach($this->collFuntFichapsicos as $referrerFK) {
						if (!$referrerFK->validate($columns)) {
							$failureMap = array_merge($failureMap, $referrerFK->getValidationFailures());
						}
					}
				}

				if ($this->collFuntFichasocials !== null) {
					foreach($this->collFuntFichasocials as $referrerFK) {
						if (!$referrerFK->validate($columns)) {
							$failureMap = array_merge($failureMap, $referrerFK->getValidationFailures());
						}
					}
				}


			$this->alreadyInValidation = false;
		}

		return (!empty($failureMap) ? $failureMap : true);
	}

	
	public function getByName($name, $type = BasePeer::TYPE_PHPNAME)
	{
		$pos = FunrProfesionalPeer::translateFieldName($name, $type, BasePeer::TYPE_NUM);
		return $this->getByPosition($pos);
	}

	
	public function getByPosition($pos)
	{
		switch($pos) {
			case 0:
				return $this->getFunrProfesionalId();
				break;
			case 1:
				return $this->getFunproNombre();
				break;
			case 2:
				return $this->getFunproApellido();
				break;
			case 3:
				return $this->getFunproSexo();
				break;
			case 4:
				return $this->getFunproEdad();
				break;
			case 5:
				return $this->getFunproTelefono();
				break;
			case 6:
				return $this->getFunproEstado();
				break;
			case 7:
				return $this->getFunrTipoprofesionalId();
				break;
			default:
				return null;
				break;
		} 	}

	
	public function toArray($keyType = BasePeer::TYPE_PHPNAME)
	{
		$keys = FunrProfesionalPeer::getFieldNames($keyType);
		$result = array(
			$keys[0] => $this->getFunrProfesionalId(),
			$keys[1] => $this->getFunproNombre(),
			$keys[2] => $this->getFunproApellido(),
			$keys[3] => $this->getFunproSexo(),
			$keys[4] => $this->getFunproEdad(),
			$keys[5] => $this->getFunproTelefono(),
			$keys[6] => $this->getFunproEstado(),
			$keys[7] => $this->getFunrTipoprofesionalId(),
		);
		return $result;
	}

	
	public function setByName($name, $value, $type = BasePeer::TYPE_PHPNAME)
	{
		$pos = FunrProfesionalPeer::translateFieldName($name, $type, BasePeer::TYPE_NUM);
		return $this->setByPosition($pos, $value);
	}

	
	public function setByPosition($pos, $value)
	{
		switch($pos) {
			case 0:
				$this->setFunrProfesionalId($value);
				break;
			case 1:
				$this->setFunproNombre($value);
				break;
			case 2:
				$this->setFunproApellido($value);
				break;
			case 3:
				$this->setFunproSexo($value);
				break;
			case 4:
				$this->setFunproEdad($value);
				break;
			case 5:
				$this->setFunproTelefono($value);
				break;
			case 6:
				$this->setFunproEstado($value);
				break;
			case 7:
				$this->setFunrTipoprofesionalId($value);
				break;
		} 	}

	
	public function fromArray($arr, $keyType = BasePeer::TYPE_PHPNAME)
	{
		$keys = FunrProfesionalPeer::getFieldNames($keyType);

		if (array_key_exists($keys[0], $arr)) $this->setFunrProfesionalId($arr[$keys[0]]);
		if (array_key_exists($keys[1], $arr)) $this->setFunproNombre($arr[$keys[1]]);
		if (array_key_exists($keys[2], $arr)) $this->setFunproApellido($arr[$keys[2]]);
		if (array_key_exists($keys[3], $arr)) $this->setFunproSexo($arr[$keys[3]]);
		if (array_key_exists($keys[4], $arr)) $this->setFunproEdad($arr[$keys[4]]);
		if (array_key_exists($keys[5], $arr)) $this->setFunproTelefono($arr[$keys[5]]);
		if (array_key_exists($keys[6], $arr)) $this->setFunproEstado($arr[$keys[6]]);
		if (array_key_exists($keys[7], $arr)) $this->setFunrTipoprofesionalId($arr[$keys[7]]);
	}

	
	public function buildCriteria()
	{
		$criteria = new Criteria(FunrProfesionalPeer::DATABASE_NAME);

		if ($this->isColumnModified(FunrProfesionalPeer::FUNR_PROFESIONAL_ID)) $criteria->add(FunrProfesionalPeer::FUNR_PROFESIONAL_ID, $this->funr_profesional_id);
		if ($this->isColumnModified(FunrProfesionalPeer::FUNPRO_NOMBRE)) $criteria->add(FunrProfesionalPeer::FUNPRO_NOMBRE, $this->funpro_nombre);
		if ($this->isColumnModified(FunrProfesionalPeer::FUNPRO_APELLIDO)) $criteria->add(FunrProfesionalPeer::FUNPRO_APELLIDO, $this->funpro_apellido);
		if ($this->isColumnModified(FunrProfesionalPeer::FUNPRO_SEXO)) $criteria->add(FunrProfesionalPeer::FUNPRO_SEXO, $this->funpro_sexo);
		if ($this->isColumnModified(FunrProfesionalPeer::FUNPRO_EDAD)) $criteria->add(FunrProfesionalPeer::FUNPRO_EDAD, $this->funpro_edad);
		if ($this->isColumnModified(FunrProfesionalPeer::FUNPRO_TELEFONO)) $criteria->add(FunrProfesionalPeer::FUNPRO_TELEFONO, $this->funpro_telefono);
		if ($this->isColumnModified(FunrProfesionalPeer::FUNPRO_ESTADO)) $criteria->add(FunrProfesionalPeer::FUNPRO_ESTADO, $this->funpro_estado);
		if ($this->isColumnModified(FunrProfesionalPeer::FUNR_TIPOPROFESIONAL_ID)) $criteria->add(FunrProfesionalPeer::FUNR_TIPOPROFESIONAL_ID, $this->funr_tipoprofesional_id);

		return $criteria;
	}

	
	public function buildPkeyCriteria()
	{
		$criteria = new Criteria(FunrProfesionalPeer::DATABASE_NAME);

		$criteria->add(FunrProfesionalPeer::FUNR_PROFESIONAL_ID, $this->funr_profesional_id);

		return $criteria;
	}

	
	public function getPrimaryKey()
	{
		return $this->getFunrProfesionalId();
	}

	
	public function setPrimaryKey($key)
	{
		$this->setFunrProfesionalId($key);
	}

	
	public function copyInto($copyObj, $deepCopy = false)
	{

		$copyObj->setFunproNombre($this->funpro_nombre);

		$copyObj->setFunproApellido($this->funpro_apellido);

		$copyObj->setFunproSexo($this->funpro_sexo);

		$copyObj->setFunproEdad($this->funpro_edad);

		$copyObj->setFunproTelefono($this->funpro_telefono);

		$copyObj->setFunproEstado($this->funpro_estado);

		$copyObj->setFunrTipoprofesionalId($this->funr_tipoprofesional_id);


		if ($deepCopy) {
									$copyObj->setNew(false);

			foreach($this->getFuntFichapsicos() as $relObj) {
				$copyObj->addFuntFichapsico($relObj->copy($deepCopy));
			}

			foreach($this->getFuntFichasocials() as $relObj) {
				$copyObj->addFuntFichasocial($relObj->copy($deepCopy));
			}

		} 

		$copyObj->setNew(true);

		$copyObj->setFunrProfesionalId(NULL); 
	}

	
	public function copy($deepCopy = false)
	{
				$clazz = get_class($this);
		$copyObj = new $clazz();
		$this->copyInto($copyObj, $deepCopy);
		return $copyObj;
	}

	
	public function getPeer()
	{
		if (self::$peer === null) {
			self::$peer = new FunrProfesionalPeer();
		}
		return self::$peer;
	}

	
	public function setFunrTipoprofesional($v)
	{


		if ($v === null) {
			$this->setFunrTipoprofesionalId(NULL);
		} else {
			$this->setFunrTipoprofesionalId($v->getFunrTipoprofesionalId());
		}


		$this->aFunrTipoprofesional = $v;
	}


	
	public function getFunrTipoprofesional($con = null)
	{
		if ($this->aFunrTipoprofesional === null && ($this->funr_tipoprofesional_id !== null)) {
						include_once 'lib/model/om/BaseFunrTipoprofesionalPeer.php';

			$this->aFunrTipoprofesional = FunrTipoprofesionalPeer::retrieveByPK($this->funr_tipoprofesional_id, $con);

			
		}
		return $this->aFunrTipoprofesional;
	}

	
	public function initFuntFichapsicos()
	{
		if ($this->collFuntFichapsicos === null) {
			$this->collFuntFichapsicos = array();
		}
	}

	
	public function getFuntFichapsicos($criteria = null, $con = null)
	{
				include_once 'lib/model/om/BaseFuntFichapsicoPeer.php';
		if ($criteria === null) {
			$criteria = new Criteria();
		}
		elseif ($criteria instanceof Criteria)
		{
			$criteria = clone $criteria;
		}

		if ($this->collFuntFichapsicos === null) {
			if ($this->isNew()) {
			   $this->collFuntFichapsicos = array();
			} else {

				$criteria->add(FuntFichapsicoPeer::FUNR_PROFESIONAL_ID, $this->getFunrProfesionalId());

				FuntFichapsicoPeer::addSelectColumns($criteria);
				$this->collFuntFichapsicos = FuntFichapsicoPeer::doSelect($criteria, $con);
			}
		} else {
						if (!$this->isNew()) {
												

				$criteria->add(FuntFichapsicoPeer::FUNR_PROFESIONAL_ID, $this->getFunrProfesionalId());

				FuntFichapsicoPeer::addSelectColumns($criteria);
				if (!isset($this->lastFuntFichapsicoCriteria) || !$this->lastFuntFichapsicoCriteria->equals($criteria)) {
					$this->collFuntFichapsicos = FuntFichapsicoPeer::doSelect($criteria, $con);
				}
			}
		}
		$this->lastFuntFichapsicoCriteria = $criteria;
		return $this->collFuntFichapsicos;
	}

	
	public function countFuntFichapsicos($criteria = null, $distinct = false, $con = null)
	{
				include_once 'lib/model/om/BaseFuntFichapsicoPeer.php';
		if ($criteria === null) {
			$criteria = new Criteria();
		}
		elseif ($criteria instanceof Criteria)
		{
			$criteria = clone $criteria;
		}

		$criteria->add(FuntFichapsicoPeer::FUNR_PROFESIONAL_ID, $this->getFunrProfesionalId());

		return FuntFichapsicoPeer::doCount($criteria, $distinct, $con);
	}

	
	public function addFuntFichapsico(FuntFichapsico $l)
	{
		$this->collFuntFichapsicos[] = $l;
		$l->setFunrProfesional($this);
	}


	
	public function getFuntFichapsicosJoinFuntCaso($criteria = null, $con = null)
	{
				include_once 'lib/model/om/BaseFuntFichapsicoPeer.php';
		if ($criteria === null) {
			$criteria = new Criteria();
		}
		elseif ($criteria instanceof Criteria)
		{
			$criteria = clone $criteria;
		}

		if ($this->collFuntFichapsicos === null) {
			if ($this->isNew()) {
				$this->collFuntFichapsicos = array();
			} else {

				$criteria->add(FuntFichapsicoPeer::FUNR_PROFESIONAL_ID, $this->getFunrProfesionalId());

				$this->collFuntFichapsicos = FuntFichapsicoPeer::doSelectJoinFuntCaso($criteria, $con);
			}
		} else {
									
			$criteria->add(FuntFichapsicoPeer::FUNR_PROFESIONAL_ID, $this->getFunrProfesionalId());

			if (!isset($this->lastFuntFichapsicoCriteria) || !$this->lastFuntFichapsicoCriteria->equals($criteria)) {
				$this->collFuntFichapsicos = FuntFichapsicoPeer::doSelectJoinFuntCaso($criteria, $con);
			}
		}
		$this->lastFuntFichapsicoCriteria = $criteria;

		return $this->collFuntFichapsicos;
	}

	
	public function initFuntFichasocials()
	{
		if ($this->collFuntFichasocials === null) {
			$this->collFuntFichasocials = array();
		}
	}

	
	public function getFuntFichasocials($criteria = null, $con = null)
	{
				include_once 'lib/model/om/BaseFuntFichasocialPeer.php';
		if ($criteria === null) {
			$criteria = new Criteria();
		}
		elseif ($criteria instanceof Criteria)
		{
			$criteria = clone $criteria;
		}

		if ($this->collFuntFichasocials === null) {
			if ($this->isNew()) {
			   $this->collFuntFichasocials = array();
			} else {

				$criteria->add(FuntFichasocialPeer::FUNR_PROFESIONAL_ID, $this->getFunrProfesionalId());

				FuntFichasocialPeer::addSelectColumns($criteria);
				$this->collFuntFichasocials = FuntFichasocialPeer::doSelect($criteria, $con);
			}
		} else {
						if (!$this->isNew()) {
												

				$criteria->add(FuntFichasocialPeer::FUNR_PROFESIONAL_ID, $this->getFunrProfesionalId());

				FuntFichasocialPeer::addSelectColumns($criteria);
				if (!isset($this->lastFuntFichasocialCriteria) || !$this->lastFuntFichasocialCriteria->equals($criteria)) {
					$this->collFuntFichasocials = FuntFichasocialPeer::doSelect($criteria, $con);
				}
			}
		}
		$this->lastFuntFichasocialCriteria = $criteria;
		return $this->collFuntFichasocials;
	}

	
	public function countFuntFichasocials($criteria = null, $distinct = false, $con = null)
	{
				include_once 'lib/model/om/BaseFuntFichasocialPeer.php';
		if ($criteria === null) {
			$criteria = new Criteria();
		}
		elseif ($criteria instanceof Criteria)
		{
			$criteria = clone $criteria;
		}

		$criteria->add(FuntFichasocialPeer::FUNR_PROFESIONAL_ID, $this->getFunrProfesionalId());

		return FuntFichasocialPeer::doCount($criteria, $distinct, $con);
	}

	
	public function addFuntFichasocial(FuntFichasocial $l)
	{
		$this->collFuntFichasocials[] = $l;
		$l->setFunrProfesional($this);
	}


	
	public function getFuntFichasocialsJoinFuntCaso($criteria = null, $con = null)
	{
				include_once 'lib/model/om/BaseFuntFichasocialPeer.php';
		if ($criteria === null) {
			$criteria = new Criteria();
		}
		elseif ($criteria instanceof Criteria)
		{
			$criteria = clone $criteria;
		}

		if ($this->collFuntFichasocials === null) {
			if ($this->isNew()) {
				$this->collFuntFichasocials = array();
			} else {

				$criteria->add(FuntFichasocialPeer::FUNR_PROFESIONAL_ID, $this->getFunrProfesionalId());

				$this->collFuntFichasocials = FuntFichasocialPeer::doSelectJoinFuntCaso($criteria, $con);
			}
		} else {
									
			$criteria->add(FuntFichasocialPeer::FUNR_PROFESIONAL_ID, $this->getFunrProfesionalId());

			if (!isset($this->lastFuntFichasocialCriteria) || !$this->lastFuntFichasocialCriteria->equals($criteria)) {
				$this->collFuntFichasocials = FuntFichasocialPeer::doSelectJoinFuntCaso($criteria, $con);
			}
		}
		$this->lastFuntFichasocialCriteria = $criteria;

		return $this->collFuntFichasocials;
	}

} 